
package com.liy.supercloud.ssoserver.controller;

import com.liy.cloud.system.entity.SysPermissionEntity;
import com.liy.cloud.system.service.SysPermissionService;
import com.liy.framework.common.annotation.IgnoreUserToken;
import com.liy.framework.common.exception.NotAuthorizationException;
import com.liy.framework.common.extvo.ResultVO;
import com.liy.framework.common.redis.utils.RedisUtils;
import com.liy.framework.web.spring.controller.SupportController;
import com.liy.supercloud.ssoserver.service.RolePermissionService;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


/**
*  用户的资源 ( 包括 ,菜单,角色 )
*/
@RestController
@RequestMapping({"/auth/resources"})
public class UserResourcesController extends SupportController {

    @Autowired
    private RedisUtils redisUtils;


    @Autowired
    private RolePermissionService rolePermissionService;


    @Autowired
    private SysPermissionService sysPermissionService;


    public static List<SysPermissionEntity> sharePermissionList = new ArrayList();


    @RequestMapping({"/menu"})
    @ResponseBody
    public ResultVO menu() throws NotAuthorizationException {
        ResultVO resultVO = new ResultVO();
        return resultVO;
    }

    @RequestMapping({"/permission"})
    @ResponseBody
    public ResultVO permission() throws NotAuthorizationException {
        ResultVO resultVO = new ResultVO();
        return resultVO;
    }

    @IgnoreUserToken
    @RequestMapping({"/permission/web"})
    @ResponseBody
    public ResultVO permissionWeb() throws NotAuthorizationException {
        ResultVO resultVO = new ResultVO();
        String[] roles = new String[]{"1f22507a64d54114affb19671e3de6ac"};
        Map<Object, Object> shareMap = this.rolePermissionService.findSharePermission((String)null);
        Map<Object, Object> rolesMap = this.rolePermissionService.findRolesPermission(roles);
        shareMap.putAll(rolesMap);
        resultVO.setData(shareMap);
        return resultVO;
    }

    @RequestMapping({"/sync"})
    @ResponseBody
    public ResultVO sync(@RequestBody List<SysPermissionEntity> list) {
        ResultVO resultVO = new ResultVO();
        sysPermissionService.savePermissionList(list);
        resultVO.setMessage("权限同步成功.");
        return resultVO;
    }

    @RequestMapping({"/sync-shared"})
    @ResponseBody
    public ResultVO syncShare() {
        ResultVO resultVO = new ResultVO();
        resultVO.setMessage("同步共享权限成功.");
        return resultVO;
    }
}
